﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using QLChoDiaOc.Process;

namespace QLChoDiaOc.Forms
{
    /// <summary>
    /// Interaction logic for WinPhieuDangKy.xaml
    /// </summary>
    public partial class WinPhieuDangKy : Window
    {
        private GetID _getId = new GetID();
        private SelectInfo _selectInfo = new SelectInfo();
        private InsertInfo _insertInfo = new InsertInfo();

        public WinPhieuDangKy()
        {
            InitializeComponent();
            HienThiThongTin();
        }

        private System.Data.Objects.ObjectQuery<PHIEUDANGKY> GetPHIEUDANGKiesQuery(QLChoDiaOcEntities qLChoDiaOcEntities)
        {
            // Auto generated code

            System.Data.Objects.ObjectQuery<QLChoDiaOc.PHIEUDANGKY> pHIEUDANGKiesQuery = qLChoDiaOcEntities.PHIEUDANGKies;
            // To explicitly load data, you may need to add Include methods like below:
            // pHIEUDANGKiesQuery = pHIEUDANGKiesQuery.Include("PHIEUDANGKies.DIAOC").
            // For more information, please see http://go.microsoft.com/fwlink/?LinkId=157380
            // Returns an ObjectQuery.
            return pHIEUDANGKiesQuery;
        }

        void HienThiThongTin()
        {
            maDangKyTextBox.Text = _getId.GenerateMaPhieuDangKy();
            maDiaOcTextBox.Text = App.DiaOcTemp.MaDiaOc; //App.Madiaoc.ToString();
            ngayDangKyDatePicker.SelectedDate = DateTime.Now;
            if (App.IsChupAnh == true)
                ngayHenDatePicker.SelectedDate = DateTime.Now.AddDays(_selectInfo.SelectThamSo_SoNgayHenChupAnhToiDa());
            else
            {
                ngayHenDatePicker.Visibility = Visibility.Collapsed;
                ngayHenLabel.Visibility = Visibility.Collapsed;
            }
        }

        //private void Window_Loaded(object sender, RoutedEventArgs e)
        //{

        //    QLChoDiaOc.QLChoDiaOcEntities qLChoDiaOcEntities = new QLChoDiaOc.QLChoDiaOcEntities();
        //    // Load data into PHIEUDANGKies. You can modify this code as needed.
        //    System.Windows.Data.CollectionViewSource pHIEUDANGKiesViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("pHIEUDANGKiesViewSource")));
        //    System.Data.Objects.ObjectQuery<QLChoDiaOc.PHIEUDANGKY> pHIEUDANGKiesQuery = this.GetPHIEUDANGKiesQuery(qLChoDiaOcEntities);
        //    pHIEUDANGKiesViewSource.Source = pHIEUDANGKiesQuery.Execute(System.Data.Objects.MergeOption.AppendOnly);
        //}

        private void btnThemPDK_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                App.PhieuDangKyTemp.MaDangKy = maDangKyTextBox.Text;
                App.PhieuDangKyTemp.MaDiaOc = maDiaOcTextBox.Text;
                App.PhieuDangKyTemp.NgayDangKy = ngayDangKyDatePicker.SelectedDate;
                if (App.QcBaoTemp.CoHinhAnh == 1)
                    App.PhieuDangKyTemp.NgayHen = ngayHenDatePicker.SelectedDate;

                App.Mainform.btnXacNhanGiayTo.IsEnabled = true;

                App.QcBangTemp.MaDangKy = maDangKyTextBox.Text;
                App.QcBaoTemp.MaDangKy = maDangKyTextBox.Text;

                App.QcToBuomTemp.MaDangKy = maDangKyTextBox.Text;

                App.PhieuThuTemp.MaDangKy = maDangKyTextBox.Text;
                App.PhieuThuTemp.NgayThu = ngayDangKyDatePicker.SelectedDate;


                MessageBox.Show("Thông tin hợp lệ", "Thông Báo");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Thông Báo");
            }
            this.Close();
        }
    }
}
